package cn.fintecher.pangolin.service.manage.request;

import cn.fintecher.pangolin.common.enums.BaseStatus;
import cn.fintecher.pangolin.entity.mysql.QPrincipal;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.util.Objects;

/**
 * @Auther: xiaqun
 * @Description: 查询委托方请求
 * @Date: 11:05 2019/8/15
 */

@Data
public class FindPrincipalRequest {
    @ApiModelProperty(value = "名称")
    private String name;

    @ApiModelProperty(value = "联系电话")
    private String phone;

    @ApiModelProperty(value = "状态")
    private BaseStatus status;

    public BooleanBuilder getBuilder() {
        BooleanBuilder builder = new BooleanBuilder();
        QPrincipal qPrincipal = QPrincipal.principal;
        if (StringUtils.isNotBlank(this.name)) {
            builder.and(qPrincipal.name.like("%" + this.name + "%"));
        }
        if (StringUtils.isNotBlank(this.phone)) {
            builder.and(qPrincipal.phone.like("%" + this.phone + "%"));
        }
        if (Objects.nonNull(this.status)) {
            builder.and(qPrincipal.status.eq(this.status));
        }
        return builder;
    }
}
